home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1998 July
/
EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso
/
earkit
/
news
/
thor
/
hd-install
/
thor.lha
/
rexx
/
BBSRead
/
RunCommand.br
< prev
next >
Wrap
Text File
|
1997-08-29
|
3KB
|
134 lines
/*
** $VER: RunCommand.br 1.41 (13.5.97)
**
** Intended for use as an SortMail external script, but can be used from the
** Shell as well. Also servers as an example of how to create external
** scripts for SortMail.
**
** See SortMail.guide for documentation
**
*/
/*
** INITIALIZATION
*/
options results
signal on syntax
signal on break_c
signal on halt
options failat 30
parse arg arguments /* Get command line arguments */
template = 'COMMAND/A,OPTIONS/K,ASYNC/S' /* READARGS template */
/*
** Check if BBSREAD's ARexx port is open, open it if it's not
*/
if ~show('P', 'BBSREAD') then do
address(command)
'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
if exists('SYS:RexxC/WaitForPort') then 'SYS:RexxC/WaitForPort BBSREAD'
else 'WaitForPort BBSREAD'
if (rc = 5) then do; say 'Could not open BBSREAD''s ARexx port.'; exit(30); end
if (rc ~= 0) then do; say 'Could not find SYS:Rexxc/WaitForPort.'; exit(30); end
end
/*
** Parse command line
*/
args.ASYNC = 0 /* Switches are set to 0 so if tests can
be performed on them, like below */
address(bbsread)
'READARGS TEMPLATE "'template'" STEM 'args' CMDLINE 'arguments
if rc ~= 0 then do
say 'READARGS failed: 'BBSREAD.LASTERROR
say 'Template: 'template
say 'RunCommand.br is an external script for SortMail.'
exit(rc)
end
/*
** MAIN CODE - substitute with your own
*/
/*
** Create the command line
*/
if args.ASYNC then
cmdline = 'Run >NIL: "' || args.COMMAND || '" >T:RunCommand.out'
else
cmdline = '"' || args.COMMAND || '" >T:RunCommand.out'
if symbol('args.OPTIONS') = 'VAR' then
cmdline = cmdline || ' ' || args.OPTIONS
/*
** Execute the command line
*/
address command cmdline
if rc ~= 0 then do
commandrc = rc
erropen = open(ef, 'T:RunCommand.out', 'R')
if erropen then do
say 'External script RunCommand.br failed: 'readln(ef)
call close(ef)
if exists('T:RunCommand.result') then
address command 'Delete "T:RunCommand.out" QUIET'
end
else
say 'External script RunCommand.br failed: Unknown error'
exit(commandrc)
end
/*
** Skip to cleanup: to do a clean exit
*/
signal cleanup
/*
** ERROR HANDLING AND EXITING
*/
/*
** Error handling routine
*/
error:
syntax:
/*
** Show BBSREAD, THOR or ARexx error
*/
select
when symbol('BBSREAD.LASTERROR') = 'VAR' then
say 'BBSREAD returned 'rc' in line 'sigl': 'BBSREAD.LASTERROR
when symbol('THOR.LASTERROR') = 'VAR' then
say 'THOR returned 'rc' in line 'sigl': 'THOR.LASTERROR
otherwise say 'Error 'rc' in line 'sigl': 'errortext(rc)
end
/*
** Leave script, returning the proper error code (if any)
*/
cleanup:
break_c:
halt:
if symbol('rc') = 'VAR' then exit(rc)
else exit(0)